import { ApiProperty } from '@midwayjs/swagger'

import { ResultVO, UserVO } from '@/vo'

/**
 * 菜单额外信息
 */
class MetaVO implements IMetaVO {
  @ApiProperty({ description: '标题' })
  title: string

  @ApiProperty({ description: '图标' })
  icon: string

  @ApiProperty({ description: '排序' })
  sort: number

  @ApiProperty({ description: '是否隐藏' })
  hidden: boolean

  @ApiProperty({ description: '是否缓存' })
  noCache: boolean

  @ApiProperty({ description: '是否一直显示' })
  alwaysShow: boolean
}

/**
 * 用户菜单结果
 */
class UserMenuVO implements IUserMenu {
  @ApiProperty({ description: '标识' })
  key: string

  @ApiProperty({ description: '父级标识' })
  parentKey: string

  @ApiProperty({ description: '路由地址' })
  path: string

  @ApiProperty({ description: '组件名称' })
  name: string

  @ApiProperty({ description: '跳转地址' })
  redirect: string

  @ApiProperty({ description: '组件路径' })
  component: string

  @ApiProperty({ description: '额外信息', type: MetaVO })
  meta: any

  @ApiProperty({
    description: '子菜单，类型参照 UserMenuVO',
    type: 'array',
    items: { type: 'string' }
  })
  children: UserMenuVO[]
}

/**
 * 用户信息结果
 */
class UserInfoVO implements IUserInfoVO {
  @ApiProperty({
    description: '菜单列表',
    type: [UserMenuVO]
  })
  menus: UserMenuVO[]

  @ApiProperty({
    description: '角色列表',
    type: 'array',
    items: { type: 'string' }
  })
  roles: string[]

  @ApiProperty({
    description: '权限列表',
    type: 'array',
    items: { type: 'string' }
  })
  permissions: string[]

  @ApiProperty({ description: '用户信息', type: UserVO })
  user: any
}

/**
 * 获取用户信息结果
 */
export class GetUserInfoVO extends ResultVO(UserInfoVO) {}
